/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ids.dl;

import ids.util.Config;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author isuru
 */
public class Server implements IServer{

    HashMap<String, SementicSearch> clientProcesses;
    private InetAddress ip;
    
    public Server()
    {
        try {
            this .ip = InetAddress.getLocalHost();
        } catch (UnknownHostException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
        clientProcesses = new HashMap<String, SementicSearch>();
    }

    public String isActive(){
        System.out.println("I'm active... ");
        return "OK";
    }   

    public ArrayList<String> doSearch(final String keyWord, final ArrayList<String> filePaths, final String clientId)
    {
        SementicSearch ss = new SementicSearch();
        clientProcesses.put(clientId, ss);
        return ss.doSearch(keyWord,filePaths);
    }

    public void stopSearch(String clientId){
        clientProcesses.get(clientId).stopSearch();
    }

    public double voteForCoordinator(){
        return ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
    }
    
    public double voteForExtraWork(){
        return ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
    }

    /**
     * @return the ip
     */
    public InetAddress getIp() {
        return ip;
    }

    /**
     * @param ip the ip to set
     */
    public void setIp(InetAddress ip) {
        this.ip = ip;
    }
}
